package com.iotproject.forumservice.controller;


import com.iotproject.commonutils.R;
import com.iotproject.forumservice.entity.ForumComment;
import com.iotproject.forumservice.entity.vo.ReplyInFirstLevelVo;
import com.iotproject.forumservice.entity.vo.SecondLevelCommentsVo;
import com.iotproject.forumservice.service.ForumCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 论坛评论回复 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2023-04-13
 */
@RestController
@RequestMapping("/forumservice/forum-comment")
public class ForumCommentController {

    @Autowired
    ForumCommentService forumCommentService;

    @PostMapping("insertComment")
    public R insertComment(@RequestBody ForumComment forumComment) {
        boolean save = forumCommentService.save(forumComment);
        if (save) {
            return R.ok();
        } else {
            return R.error();
        }
    }

    @GetMapping("getList/{questionId}/{parentId}/{userDesc}")
    public R getList(@PathVariable("questionId") String questionId, @PathVariable("parentId") String parentId, @PathVariable("userDesc") String userDesc) {
        List<SecondLevelCommentsVo> list = forumCommentService.getList(questionId, parentId, userDesc);
        return R.ok().data("list", list);
    }

    //评论(一二级列表的评论方法皆可使用，只需改变 ReplyInFirstLevelVo 的值即可(后续可以在VSCode 里改下方法名称，这里先不改))
    @PostMapping("replyOperatorInFirstLeve")
    public R replyOperatorInFirstLeve(@RequestBody ReplyInFirstLevelVo replyInFirstLevelVo) {
        return forumCommentService.replyOperatorInFirstLeve(replyInFirstLevelVo);
    }

    //点赞
    @PostMapping("likeOperator/{forumCommentId}")
    public R likeOperator(@PathVariable("forumCommentId") String forumCommentId) {
        return forumCommentService.likeOperator(forumCommentId);
    }

    //取消点赞
    @PostMapping("cancelLikeOperator/{forumCommentId}")
    public R cancelLikeOperator(@PathVariable("forumCommentId") String forumCommentId) {
        return forumCommentService.cancelLikeOperator(forumCommentId);
    }

}

